import time

import pytest

import page
from page.page_in import PageIn
from tools.get_driver import GetDriver
from tools.get_log import GetLog
from tools.read_yaml import read_yaml
log  = GetLog.get_logger()


class TestAxaSubmitOrder:
    # 初始化
    def setup_class(self):
        driver = GetDriver.get_web_driver(page.axa_uat_homepage_url)
        self.page_in = PageIn(driver)

    # 结束
    def teardown_class(self):
        time.sleep(3)
        # GetDriver.quit_web_driver()

    @pytest.mark.parametrize('title, cname, axa_personnelName, axa_licenceNo, expect', read_yaml('axa_homepage.yaml'))
    def test_axa_homepage(self, title, cname, axa_personnelName, axa_licenceNo, expect):
        self.homepage = self.page_in.page_get_PageAxaHomePage()
        self.homepage.page_axa_homepage(title, cname, axa_personnelName, axa_licenceNo)

    @pytest.mark.parametrize('runCardCertificateDate,vehicleFrameNo,engineNo,firstRegisterDate,'
                             'showFormatCertificateNo,showFormatTelephone,expect',
                             read_yaml('axa_write_info.yaml'))
    def test_axa_write_info(self, runCardCertificateDate, vehicleFrameNo, engineNo,
                            firstRegisterDate, showFormatCertificateNo, showFormatTelephone, expect):
        time.sleep(2)
        self.writeinfo = self.page_in.page_get_PageAxaWriteInfo()
        self.writeinfo.page_axa_write_info(runCardCertificateDate, vehicleFrameNo,
                                                                     engineNo, firstRegisterDate,
                                                                     showFormatCertificateNo, showFormatTelephone)
        try:
            assert expect == self.writeinfo.page_get_text()
        except Exception as e:
            log.error("断言异常问题:{}".format(e))
            self.writeinfo.base_get_image()
            raise

    @pytest.mark.parametrize('expects', read_yaml('axa_select_quotation.yaml'))
    def test_axa_select_quotation(self, expects):
        self.selectquotation = self.page_in.page_get_PageAxaSelectQuotation()
        self.selectquotation.page_axa_select_quotation()
        try:
            assert expects in self.selectquotation.page_get_text()
        except Exception as e:
            log.error("断言异常问题:{}".format(e))
            self.selectquotation.base_get_image()
            raise

    # @pytest.mark.parametrize('email,address,validCode', read_yaml('axa_submit_order.yaml'))
    # def test_axa_submit_order(self, email, address, validCode):
    #     self.page_in.page_get_PageAxaSubmitOrder().page_axa_submit_order(email, address, validCode)
